<?php 
/**
 * Created with sublime
 * Author: yinni
 * Date: 2017/12/02 18:30
 */
namespace App\Services\Admin;

use Facades\App\Repositories\Eloquent\RiversRepository;
use Facades\App\Repositories\Eloquent\CoringRepository;
use Facades\App\Repositories\Eloquent\Rivers_alarm_historyRepository;
use App\Repositories\Traits\DatatableActionButtonTrait;
use Facades\Yajra\DataTables\Html\Builder;

use DataTables;
use Exception;
use DB;

class AnalysisService{
	use DatatableActionButtonTrait;

	protected $module = 'Analysis'; //模块路由

	protected $indexRoute = 'Analysis.index'; 

	// protected $showRoute = 'alarm.show';

	protected $editRoute = 'Analysis.edit';

	protected $destroyRoute = 'Analysis.destroy';
    public function __construct() {
        // 定义当前需使用的数据表
        $this->rivers_alarm_history = Rivers_alarm_historyRepository::all();      
    }
	/**
	 * 首页
	 * @return array
	 */
	public function index() {
		if(request()->ajax()) {
			return $this->ajaxData();
		}
        $html = Builder::parameters([
            'searchDelay' => 350,
            'language' => [
                'url' => url(getThemeAssets('dataTables/language/zh.json', true))
            ],
            'drawCallback' => <<<Eof
					function() {
				        LaravelDataTables["dataTableBuilder"].$('.tooltips').tooltip( {
				          placement : 'top',
				          html : true
				        });
			        },
Eof
        ])->addIndex(['data' => 'DT_Row_Index', 'name' => 'DT_Row_Index', 'title' => trans('common.number')])
            ->addColumn(['data' => 'river_id', 'name' => 'river_id', 'title' => trans('analysis.river_id')])
            ->addColumn(['data' => 'start_time', 'name' => 'start_time', 'title' => trans('analysis.start_time')])
            ->addColumn(['data' => 'confirm_time', 'name' => 'confirm_time', 'title' => trans('analysis.confirm_time')])
            ->addColumn(['data' => 'user_id', 'name' => 'user_id', 'title' => trans('analysis.user_id')])
            ->addColumn(['data' => 'status', 'name' => 'status', 'title' => trans('analysis.status')])
            ->addColumn(['data' => 'temp', 'name' => 'temp', 'title' => trans('analysis.temp')])
            ->addColumn(['data' => 'height', 'name' => 'height', 'title' => trans('analysis.height')])
            ->addColumn(['data' => 'ph', 'name' => 'ph', 'title' => trans('analysis.ph')])
            ->addColumn(['data' => 'turbidity', 'name' => 'turbidity', 'title' => trans('analysis.turbidity')]);
            return compact('html');
        }

    /**
     * datatable数据
     * @return mixed
     */
    public function ajaxData() {
    	return Datatables::of(Rivers_alarm_historyRepository::all())
			->addIndexColumn()
			->make(true);
    }

}